package com.intretech.tj.gpp.pathfinding

import jakarta.enterprise.context.ApplicationScoped
import jakarta.enterprise.inject.Any
import jakarta.enterprise.inject.Instance
import jakarta.inject.Inject

/**
 * 车辆道路选择决策工厂
 */
@ApplicationScoped
class WeightStrategyFactory @Inject constructor(
    @Any
    private val strategies: Instance<WeightStrategy>
) {
    // lazy 构建 Map<mark, strategy>
    private val strategyMap: Map<String, WeightStrategy> by lazy {
        strategies
            .iterator()                               // Instance<T> 提供迭代器
            .asSequence()                             // 转成 Kotlin Sequence
            .associateBy { it.mark() }                // 用 mark() 做 Key
    }


    fun get(type: String): WeightStrategy =
        strategyMap[type] ?: throw IllegalArgumentException("未找到策略: $type")
}